# 训练
for epoch in range(15):    
    outputs = model(inputs) # inputs:(batch,seqlen) (1,5)
    # outputs:(batch,seqlen,num_class) (1,5,4) 
    pred = outputs.view(-1, num_class)  
    # 合并两个维度：
    # batch*seqlen*num_class转化((batch*seqlen),numclass)
    # pred:((batch*seqlen),numclass) (5,4)
    loss = criterion(pred,labels)# label:(batch*seqlen)(5,)
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()
    _, idx = pred.max(dim=1) 
    # pred:((batch*seqlen),numclass) (5,4)
    # idx:(5,) 
    idx = idx.data.numpy()
    print("Pred:", ''.join([idx2char[x] for x in idx]))
    print(",Epoch {}/15 loss={:.3f}".format(epoch+1, loss.item()))
